package com.example.chengww.myone.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.chengww.myone.R;
import com.example.chengww.myone.bean.Read;

import java.util.List;

/**
 * Created by chengww on 2016/9/20.
 */
public class MyReadContentAdapter extends BaseAdapter {

    private List<Read.Data.Essay> essay;
    private List<Read.Data.Serial> serial;
    private List<Read.Data.Question> question;
    private Context context;
    private int pos;


    public MyReadContentAdapter(List<Read.Data.Essay> essay,
                                List<Read.Data.Serial> serial,
                                List<Read.Data.Question> question,
                                Context context,int pos) {
        this.essay = essay;
        this.serial = serial;
        this.question = question;
        this.context = context;
        this.pos = pos;
    }

    @Override
    public int getCount() {
        return 3;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.read_list_item, null);
            convertView.setPadding(10,15,10,15);
            viewHolder = new ViewHolder();
            viewHolder.essay_author = (TextView) convertView.findViewById(R.id.essay_author);
            viewHolder.essay_guide_word = (TextView) convertView.findViewById(R.id.essay_guide_word);
            viewHolder.hp_title = (TextView) convertView.findViewById(R.id.hp_title);
            viewHolder.img_essay = (ImageView) convertView.findViewById(R.id.img_essay);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        switch (position){
            case 0:
                viewHolder.essay_author.setText(
                        essay.get(pos).getAuthor().get(0).getUser_name());
                viewHolder.essay_author.setTextColor(context.getResources().
                        getColor(R.color.colorBlack));

                viewHolder.essay_guide_word.setText(essay.get(pos).getGuide_word());
                viewHolder.essay_guide_word.setTextColor(context.getResources().
                        getColor(R.color.colorBlack));

                viewHolder.hp_title.setText(essay.get(pos).getHp_title());
                viewHolder.hp_title.setTextColor(context.getResources().
                        getColor(R.color.colorBlack));

                viewHolder.img_essay.setImageResource(R.mipmap.essay_image);
                break;
            case 1:
                viewHolder.essay_author.setText(
                        serial.get(pos).getAuthor().getUser_name());
                viewHolder.essay_author.setTextColor(context.getResources().
                        getColor(R.color.colorBlack));

                viewHolder.essay_guide_word.setText(serial.get(pos).getExcerpt());
                viewHolder.essay_guide_word.setTextColor(context.getResources().
                        getColor(R.color.colorBlack));

                viewHolder.hp_title.setText(serial.get(pos).getTitle());
                viewHolder.hp_title.setTextColor(context.getResources().
                        getColor(R.color.colorBlack));

                viewHolder.img_essay.setImageResource(R.mipmap.serial_image);
                break;
            case 2:
                viewHolder.essay_author.setText(
                        question.get(pos).getAnswer_title());
                viewHolder.essay_author.setTextColor(context.getResources().
                        getColor(R.color.colorBlack));

                viewHolder.essay_guide_word.setText(question.get(pos).getAnswer_content());
                viewHolder.essay_guide_word.setTextColor(context.getResources().
                        getColor(R.color.colorBlack));

                viewHolder.hp_title.setText(question.get(pos).getQuestion_title());
                viewHolder.hp_title.setTextColor(context.getResources().
                        getColor(R.color.colorBlack));

                viewHolder.img_essay.setImageResource(R.mipmap.question_image);
                break;
        }
        viewHolder.essay_author.setPadding(20,0,0,10);
        viewHolder.essay_guide_word.setPadding(20,0,0,10);
        viewHolder.hp_title.setPadding(20,10,10,0);
        return convertView;
    }

    class ViewHolder {
        TextView essay_author;
        TextView essay_guide_word;
        TextView hp_title;
        ImageView img_essay;
    }
}
